package org.study.mapper.generator.common;

import tk.mybatis.mapper.additional.idlist.IdListMapper;
import tk.mybatis.mapper.common.*;

/**
 * 自己个性化的 Mapper。
 * 注意：公用 Mapper 接口需要单独存在，以便和普通 mapper 分开，以免启动类的 @MapperScan 扫描到会报错
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2021-04-22
 */
public interface CommonMapper<T> extends Mapper<T>, MySqlMapper<T>, IdsMapper<T>, IdListMapper<T, Object>, ConditionMapper<T> {
    default int deleteWithVersion(T t) {
        int result = delete(t);
        if (result == 0) {
            throw new RuntimeException("删除失败!");
        }
        return result;
    }

    default int deleteByPrimaryKeyWithVersion(T t) {
        int result = deleteByPrimaryKey(t);
        if (result == 0) {
            throw new RuntimeException("删除失败!");
        }
        return result;
    }

    default int updateByPrimaryKeyWithVersion(T t) {
        int result = updateByPrimaryKey(t);
        if (result == 0) {
            throw new RuntimeException("更新失败!");
        }
        return result;
    }

    default int updateByPrimaryKeySelectiveWithVersion(T t) {
        int result = updateByPrimaryKeySelective(t);
        if (result == 0) {
            throw new RuntimeException("更新失败!");
        }
        return result;
    }
}
